<?php


namespace App\Http\Controllers\Admin;


use Illuminate\Routing\Controller;

class BaseController extends Controller
{
    /**
     * @var string 路由前缀
     */
    protected $routePrefix = '';
    /**
     * 试图前缀
     * @var string
     */
    protected $viewPrefix = '';

    protected function set($routePrefix, $viewPrefix = '')
    {
        $this->routePrefix = $routePrefix;
        if (empty($viewPrefix)) {
            $viewPrefix = str_replace("/", ".", $routePrefix);
        }
        $this->viewPrefix = $viewPrefix;
    }

    protected function view($view, $data = [], $mergeData = [])
    {
        if (empty($this->viewPrefix)) {
            $viewPath = $view;
        } else {
            $viewPath = $this->viewPrefix . '.' . $view;
        }
        $v = view('backend.' . $viewPath, $data, $mergeData);
        if (empty($this->routePrefix)) {
            $v->with('baseRoute', 'admin/');
        } else {
            $v->with('baseRoute', 'admin/' . $this->routePrefix . '/');
        }
        return $v;
    }
}
